/**
* @authors Duong NGUYEN <darl2ng@gmail.com>, Anh NGO <ngocanh.ngo@gmail.com>
* @version 0.9
* Copyright 2010
* 
* The MIT License
* Copyright (c) 2010 <Duong NGUYEN <darl2ng@gmail.com>, Anh NGO <ngocanh.ngo@gmail.com>
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package {
	import com.ng.ui.cMenu;
	import com.ng.ui.cMenuEntry;
	import com.ng.utils.c_Mediator;
	import com.ng.utils.c_FileReader;
	import fl.controls.ComboBox;
	import flash.events.Event;
	
	public class c_MenuMediator extends c_Mediator	{
		
		private var __Menu:cMenu;
		private var __ResEditor:c_ResEditor;
		private var __FileReader:c_FileReader;
		private var __ClassList:ComboBox;
		
		public function c_MenuMediator(m:cMenu) {
			__Menu = m;
			__Menu.Mediator = this;
		}
		public function get FileReader():c_FileReader {
			return __FileReader;
		}
		public function set ResEditor(re:c_ResEditor):void {
			__ResEditor = re;
		}	
		public function set ClassList(cl:ComboBox):void {
			__ClassList = cl;
		}
		public function Activate(s:String,b:Boolean):void {
			(__Menu.getChildByName(s) as cMenuEntry).SetListener(b, "execute"+s, this);
		}		
		public function executeOpen():void {
			__FileReader = new c_FileReader();
			__FileReader.addEventListener(c_FileReader.FILE_LOADED, OnFileLoaded);
		}
		public function executeSave():void {
			if (__ResEditor) {
				__ResEditor.SaveXML("settings.xml");
			} else {
				c.e("load file first");	
			}
		}
		public function executeNew():void {
			if(__ClassList != null && __ClassList.selectedItem != null) {
				__ResEditor.newItem(__ClassList.selectedItem.label);	
			}
		}
		public function executeDelete():void {
			//trace("executeDeleteClick");
			__ResEditor.deleteCurrentSelect();		
		}
		public function executeToFront():void {
			//trace("onToFrontClick");
			__ResEditor.bringCurrentToFront();
		}
		public function executeToBack():void {
			//trace("onToBackClick");
			__ResEditor.bringCurrentToBack();
		}
		public function executeUnselect():void {
			//trace("onUnselectClick");
			__ResEditor.unSelect();
		}
		private function OnFileLoaded(e:Event):void {			
			dispatchEvent(e.clone());
		}
	}
}